n = int(input())
arr = [int(x) for x in input().split(" ")]
v = arr[0]
l = 0;
r = len(arr) - 1
lt = l
gt = r + 1
i = l + 1

while i < gt:
    if arr[i] < v:
        arr[i], arr[lt + 1] = arr[lt + 1], arr[i]
        i += 1
        lt += 1
    elif arr[i] > v:
        arr[i], arr[gt - 1] = arr[gt - 1], arr[i]
        gt -= 1
    else:
        i += 1
arr[l], arr[lt] = arr[lt], arr[l]
for num in arr:
    print(num, end=" ")
